package com.fjeld.server.ssl.impl;

import com.fjeld.middleware.activemq.QueuedMessageListener;
import com.fjeld.middleware.activemq.QueuedMessagePublisher;
import com.fjeld.middleware.constants.PropertiesManager;
import com.fjeld.server.ssl.ServerStackLayer;
import com.fjeld.server.worker.Dispatcher;
import org.apache.log4j.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: fjeld
 * Date: 11/12/2011
 * Time: 15:02
 *
 * Handles content requests and serves the content out.
 */
public class ContentHandlerStack extends AbstractServerStack implements ServerStackLayer
{
    private static final Logger LOGGER = Logger.getLogger(ContentHandlerStack.class);

    public ContentHandlerStack()
    {
        LOGGER.info("Initialising");
        String topicMessageRequest = PropertiesManager.getProperties().getProperty("Topic.Request.Prefix") + ".>";
        String topicMessageResponse = PropertiesManager.getProperties().getProperty("Topic.Response.Prefix") + "." + serverName;

        QueuedMessagePublisher qmp = new QueuedMessagePublisher(
                topicMessageResponse, serverName + ".QueuedMessageListener");
        QueuedMessageListener qml = new QueuedMessageListener(
                topicMessageRequest, serverName + ".QueuedMessageListener", qmp.getMessageQueue());

        Dispatcher dispatcher = new Dispatcher(serverName + ".QueuedMessageListener",
        qml.getMessageQueue(), qmp.getMessageQueue());

        new Thread(dispatcher).start();
        qmp.startConnection();
        qml.startConnection();
        LOGGER.info("Finished initialising");
    }
}

